package main

import "C"
import (
	"fmt"
	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
	"github.com/spf13/viper"
	"os"
	"wjp/ginandvue/common"
)



func main(){
	//fmt.Println(`hello wujiangpan`)
	InitConfig()
	db := common.InitDB()
	defer db.Close()

	r := gin.Default()

	r = CollectRoutes(r)
	port := viper.GetString("server.port")
	if port != ""{
		panic(r.Run(":"+port)) // 监听并在 0.0.0.0:8080 上启动服务
	}
	panic(r.Run()) // 监听并在 0.0.0.0:8080 上启动服务
}

func InitConfig(){
	workDir,_ := os.Getwd()
	viper.SetConfigName("application")
	viper.SetConfigType("yml")
	viper.AddConfigPath(workDir+"/config")
	err := viper.ReadInConfig()
	if err != nil{
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
}





